/**
 *  列表页
 *
 * 作者 Lujiachen
 * 日期 2024-08-13 08:53:55
 */
layui.use(['jquery', 'laydate', 'febs', 'form', 'table', 'commonJS', 'validate'], function () {
    var $ = layui.jquery,
        laydate = layui.laydate,
        febs = layui.febs,
        form = layui.form,
        table = layui.table,
        validate = layui.validate,
        $view = $('#febs-hazardExamineConfig'),
        $query = $view.find('#query'),
        $add = $view.find('#add'),
        $searchForm = $view.find('#hazardExamineConfig-search-form'),
        $tenantSelect = $searchForm.find('select[name="tenantSelect"]'),
        tableIns;
    var i=8;
    form.verify(validate);
    form.render();

    initFormValue();
    function initFormValue() {
        clearContext();
        if (hazardExamineConfigList) {
            for(let i=0;i<hazardExamineConfigList.length;i++){
                let hazardExamineConfig = hazardExamineConfigList[i];
                if(hazardExamineConfig.examineType=='1') {
                    form.val("hazardExamineConfig-table-form", {
                        "examineConfigId1": hazardExamineConfig.examineConfigId,
                        "examineNumber1": hazardExamineConfig.specialExamineNumber,
                        "examineCycl1": hazardExamineConfig.specialExamineCycl,
                        "examineNumber2": hazardExamineConfig.dailyExamineNumber,
                        "examineCycl2": hazardExamineConfig.dailyExamineCycl,
                    });
                }
                if(hazardExamineConfig.examineType=='3'){
                    form.val("hazardExamineConfig-table-form", {
                        "examineConfigId3": hazardExamineConfig.examineConfigId,
                        "examineNumber3": hazardExamineConfig.specialExamineNumber,
                        "examineCycl3": hazardExamineConfig.specialExamineCycl,
                        "examineNumber4": hazardExamineConfig.dailyExamineNumber,
                        "examineCycl4": hazardExamineConfig.dailyExamineCycl,
                    });
                    if(hazardExamineConfig.dtlConfigList.length>0){
                        $('#noticeSpanBmZx').css('display','none');
                        $('#noticeSpanBmRc').css('display','none');
                        for(let j=0;j<hazardExamineConfig.dtlConfigList.length;j++){
                            let data = hazardExamineConfig.dtlConfigList[j];
                            if(data.examineCategory == "1"){
                                appendItem("bmAddZx",data);
                            }else{
                                appendItem("bmAddRc",data);
                            }
                        }
                    }
                }
                if(hazardExamineConfig.examineType=='4'){
                    form.val("hazardExamineConfig-table-form", {
                        "examineConfigId5": hazardExamineConfig.examineConfigId,
                        "examineNumber5": hazardExamineConfig.specialExamineNumber,
                        "examineCycl5": hazardExamineConfig.specialExamineCycl,
                        "examineNumber6": hazardExamineConfig.dailyExamineNumber,
                        "examineCycl6": hazardExamineConfig.dailyExamineCycl,
                    });
                    if(hazardExamineConfig.dtlConfigList.length>0){
                        $('#noticeSpanCjZx').css('display','none');
                        $('#noticeSpanCjRc').css('display','none');
                        for(let j=0;j<hazardExamineConfig.dtlConfigList.length;j++){
                            let data = hazardExamineConfig.dtlConfigList[j];
                            if(data.examineCategory == "1"){
                                appendItem("cjAddZx",data);
                            }else{
                                appendItem("cjAddRc",data);
                            }
                        }
                    }
                }
                if(hazardExamineConfig.examineType=='5'){
                    form.val("hazardExamineConfig-table-form", {
                        "examineConfigId7": hazardExamineConfig.examineConfigId,
                        "examineNumber7": hazardExamineConfig.specialExamineNumber,
                        "examineCycl7": hazardExamineConfig.specialExamineCycl,
                        "examineNumber8": hazardExamineConfig.dailyExamineNumber,
                        "examineCycl8": hazardExamineConfig.dailyExamineCycl,
                    });
                if(hazardExamineConfig.dtlConfigList.length>0){
                    $('#noticeSpanBzZx').css('display','none');
                    $('#noticeSpanBzRc').css('display','none');
                    for(let j=0;j<hazardExamineConfig.dtlConfigList.length;j++){
                        let data = hazardExamineConfig.dtlConfigList[j];
                        if(data.examineCategory == "1"){
                            appendItem("bzAddZx",data);
                        }else{
                            appendItem("bzAddRc",data);
                        }
                    }
                }
                }
                if(hazardExamineConfig.examineType=='6'){
                    form.val("hazardExamineConfig-table-form", {
                        "examineConfigId9": hazardExamineConfig.examineConfigId,
                        "examineNumber9": hazardExamineConfig.specialExamineNumber,
                        "examineCycl9": hazardExamineConfig.specialExamineCycl,
                        "examineNumber10": hazardExamineConfig.dailyExamineNumber,
                        "examineCycl10": hazardExamineConfig.dailyExamineCycl,
                    });
                    if(hazardExamineConfig.dtlConfigList.length>0){
                        $('#noticeSpanXmZx').css('display','none');
                        $('#noticeSpanXmRc').css('display','none');
                        for(let j=0;j<hazardExamineConfig.dtlConfigList.length;j++){
                            let data = hazardExamineConfig.dtlConfigList[j];
                            if(data.examineCategory == "1"){
                                appendItem("xmAddZx",data);
                            }else{
                                appendItem("xmAddRc",data);
                            }
                        }
                    }
                }
            }
        }else {
                form.val("hazardExamineConfig-table-form", {
                    "examineConfigId1": "",
                    "examineNumber1": "1",
                    "examineCycl1": "1",
                    "examineNumber2": "1",
                    "examineCycl2": "1",

                    "examineConfigId3": "",
                    "examineNumber3": "1",
                    "examineCycl3": "1",
                    "examineNumber4": "1",
                    "examineCycl4": "1",

                    "examineConfigId5": "",
                    "examineNumber5": "1",
                    "examineCycl5": "1",
                    "examineNumber6": "1",
                    "examineCycl6": "1",

                    "examineConfigId7": "",
                    "examineNumber7": "1",
                    "examineCycl7": "1",
                    "examineNumber8": "1",
                    "examineCycl8": "1",

                    "examineConfigId9": "",
                    "examineNumber9": "1",
                    "examineCycl9": "1",
                    "examineNumber10": "1",
                    "examineCycl10": "1",
                });


        }
    }

    function clearContext(){
        var obj = document.getElementById("bmZx-item")
        obj.innerHTML="";
        obj = document.getElementById("bmRc-item")
        obj.innerHTML="";
        obj = document.getElementById("cjZx-item")
        obj.innerHTML="";
        obj = document.getElementById("cjRc-item")
        obj.innerHTML="";
        obj = document.getElementById("bzZx-item")
        obj.innerHTML="";
        obj = document.getElementById("bzRc-item")
        obj.innerHTML="";
        obj = document.getElementById("xmZx-item")
        obj.innerHTML="";
        obj = document.getElementById("xmRc-item")
        obj.innerHTML="";
    }
    function reloadPage(curr) {
        var tenantId=$tenantSelect.val();
        febs.get(ctx + 'hazardExamineConfig/search/' + tenantId, null, function (data) {
            var newHazardReportConfig = "";
            if(data.code==200&&data.data.hazardExamineConfigList.length>0){
                hazardExamineConfigList = data.data.hazardExamineConfigList;
            }else {
                hazardExamineConfigList = "";
            }
            initFormValue();
        })
    }

    $query.on('click', function () {
        reloadPage();
    });

    //部门检查拼接
    $view.find("#bmAddZx").on('click',function () {
        $('#noticeSpanBmZx').css('display','none');
        appendItem("bmAddZx","");
    })
    $view.find("#bmAddRc").on('click',function () {
        $('#noticeSpanBmRc').css('display','none');
        appendItem("bmAddRc","");
    })
    //车间检查拼接
    $view.find("#cjAddZx").on('click',function () {
        $('#noticeSpanCjZx').css('display','none');
        appendItem("cjAddZx","");
    })
    $view.find("#cjAddRc").on('click',function () {
        $('#noticeSpanCjRc').css('display','none');
        appendItem("cjAddRc","");
    })
    //班组检查拼接
    $view.find("#bzAddZx").on('click',function () {
        $('#noticeSpanBzZx').css('display','none');
        appendItem("bzAddZx","");
    })
    $view.find("#bzAddRc").on('click',function () {
        $('#noticeSpanBzRc').css('display','none');
        appendItem("bzAddRc","");
    })
    //项目检查拼接
    $view.find("#xmAddZx").on('click',function () {
        $('#noticeSpanXmZx').css('display','none');
        appendItem("xmAddZx","");
    })
    $view.find("#xmAddRc").on('click',function () {
        $('#noticeSpanXmRc').css('display','none');
        appendItem("xmAddRc","");
    })

    function appendItem(type,data) {
        let id = "examineTargetId";
        let name = "examineTargetName";
        let number = "examineNumber";
        let  cycl = "examineCycl";
        let holder = "请选择";
        let addBtn = "addBtn";
        let title = "";
        if(type=="bmAddZx"){
            id += "BmZx"+i;
            name +="BmZx"+i;
            number +="BmZx"+i;
            cycl +="BmZx"+i;
            holder+="部门";
            title = "部门";
        }else if(type=="cjAddZx"){
                id += "CjZx"+i;
                name +="CjZx"+i;
                number +="CjZx"+i;
                cycl +="CjZx"+i;
                holder+="车间";
                title="车间";
                addBtn+="2";
        }else if(type=="bzAddZx"){
                id += "BzZx"+i;
                name +="BzZx"+i;
                number +="BzZx"+i;
                cycl +="BzZx"+i;
                holder+="班组";
                title = "班组";
                addBtn+="3";
        }else if(type=="xmAddZx"){
            id += "XmZx"+i;
            name +="XmZx"+i;
            number +="XmZx"+i;
            cycl +="XmZx"+i;
            holder+="项目";
            title = "项目";
            addBtn+="4";
        }else if(type=="bmAddRc"){
            id += "BmRc"+i;
            name +="BmRc"+i;
            number +="BmRc"+i;
            cycl +="BmRc"+i;
            holder+="部门";
            title = "部门";
        }else if(type=="cjAddRc"){
            id += "CjRc"+i;
            name +="CjRc"+i;
            number +="CjRc"+i;
            cycl +="CjRc"+i;
            holder+="车间";
            title="车间";
            addBtn+="2";
        }else if(type=="bzAddRc"){
            id += "BzRc"+i;
            name +="BzRc"+i;
            number +="BzRc"+i;
            cycl +="BzRc"+i;
            holder+="班组";
            title = "班组";
            addBtn+="3";
        }else if(type=="xmAddRc"){
            id += "XmRc"+i;
            name +="XmRc"+i;
            number +="XmRc"+i;
            cycl +="XmRc"+i;
            holder+="项目";
            title = "项目";
            addBtn+="4";
        }
        let idValue="";
        let nameValue = "";
        let numberValue = "";
        if(data){
           idValue = data.examineTargetId;
           nameValue = data.examineTargetName;
           numberValue = data.examineNumber;
        }
        var item = '<div class="layui-form-item">\n' +
            '                   <div class="layui-col-md2" style="margin-left: 2%">\n'+
            '                       <div class="layui-input-inline" >\n' +
            '                          <div class="input-container">\n' +
            '                             <input type="text" name="'+id + '" value="'+idValue+'" class="febs-hide">\n' +
            '                             <input type="text" name="'+name + '" value="'+nameValue+'"autocomplete="off" class="layui-input"\n' +
            '                                     minlength="2" maxlength="10"  placeholder="请选择'+title+'" disabled>\n' +
            '                              <div class="'+addBtn+' layui-input-suffix" name="examineTarget'+i+'">\n'+
            '                                       <i class="layui-icon layui-icon-add-1"></i>\n'+
            '                               </div>\n'+
            '                              <input class="layui-form-item febs-hide" name="examineDtlConfigId' + i + '" value="'+data.examineDtlConfigId+'"></input>\n' +
            '                           </div>\n' +
            '                       </div>\n' +
            '                    </div>\n' +
            '                    <div class="layui-col-md2" style="margin-left: 10%">\n' +
            '                             <div class="layui-form-item">\n' +
            '                             <label class="layui-form-label">检查次数</label>\n' +
            '                                 <div class="layui-input-block" style="width: 150%;">\n' +
            '                                   <input type="text"   name="'+number+'" value="'+numberValue+'"autocomplete="off" class="layui-input" minlength="1"\n' +
            '                                         maxlength="4" lay-verify="range||amount"\n' +
            '                                         onkeyup="value=value.replace(/[^\\d{1,}\\d{1,}|\\d{1,}]/g,\'\').replace(/\\./g,\'\').replace(/^(\\-)*(\\d+)\\.(\\d\\d).*$/,\'$1$2.$3\')"\n' +
            '                                   >\n ' +
            '                               </div>\n' +
            '                              </div>\n' +
            '                     </div>\n' +
            '                     <div class="layui-col-md3" style="width: 70%">\n' +
            '                         <div class="layui-form-item">\n' +
            '                         <label class="layui-form-label">检查周期</label>\n' +
            '                               <div class="layui-input-block">\n' +
            '                                  <input type="radio" name="'+cycl+'" title="周" value="1" checked>\n' +
            '                                  <input type="radio" name="'+cycl+'" title="月" value="2">\n' +
            '                                  <input type="radio" name="'+cycl+'" title="季" value="3">\n' +
            '                                  <input type="radio" name="'+cycl+'" title="半年" value="4">\n' +
            '                                  <input type="radio" name="'+cycl+'" title="年" value="5">\n' +
            '                                  <div  class="deleteBtn layui-btn layui-btn-sm layui-btn-danger">\n' +
            '                                       <em class="layui-icon">&#xe640;</em>\n' +
            '                                  </div>\n' +
            '                               </div>\n' +
            '                         </div>\n' +
            '                    </div>\n' +
            '              <hr class="layui-bg-orange">'+
            '              </div>';

        if(type=="bmAddZx"){
            $view.find("#bmZx-item").append(item);
        }else if(type=="cjAddZx"){
            $view.find("#cjZx-item").append(item);
        }else if(type=="bzAddZx"){
            $view.find("#bzZx-item").append(item);
        }else if(type=="xmAddZx"){
            $view.find("#xmZx-item").append(item);
        }else if(type=="bmAddRc"){
            $view.find("#bmRc-item").append(item);
        }else if(type=="cjAddRc"){
            $view.find("#cjRc-item").append(item);
        }else if(type=="bzAddRc"){
            $view.find("#bzRc-item").append(item);
        }else if(type=="xmAddRc"){
            $view.find("#xmRc-item").append(item);
        }

        $("input[name='"+cycl+"']").each(function(index,element){
            if($(this).val()==data.examineCycl){
                $(this).prop("checked",true);
            }
        })
        i++;

        form.render();
    }

    function removeItem(_e) {
        $(_e).parent().parent().parent().parent().remove();
    }

    $view.find("#bmZx-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#bmZx-item').children('.layui-form-item').length == 0){
            $('#noticeSpanBmZx').css('display','');
        }
    })
    $view.find("#bmRc-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#bmRc-item').children('.layui-form-item').length == 0){
            $('#noticeSpanBmRc').css('display','');
        }
    })
    $view.find("#cjZx-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#cjZx-item').children('.layui-form-item').length == 0){
            $('#noticeSpanCjZx').css('display','');
        }
    })
    $view.find("#cjRc-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#cjRc-item').children('.layui-form-item').length == 0){
            $('#noticeSpanCjRc').css('display','');
        }
    })
    $view.find("#bzZx-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#bzZx-item').children('.layui-form-item').length == 0){
            $('#noticeSpanBzZx').css('display','');
        }
    })
    $view.find("#bzRc-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#bzRc-item').children('.layui-form-item').length == 0){
            $('#noticeSpanBzRc').css('display','');
        }
    })
    $view.find("#xmZx-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#xmZx-item').children('.layui-form-item').length == 0){
            $('#noticeSpanXmZx').css('display','');
        }
    })
    $view.find("#xmRc-item").on('click','.deleteBtn',function () {
        removeItem(this);
        if($('#xmRc-item').children('.layui-form-item').length == 0){
            $('#noticeSpanXmRc').css('display','');
        }
    })

    //部门点击事件
    $view.find("#bmZx-item").on('click','.addBtn',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('部门选择', '/common/dept', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['500px','600px'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameBmZx"+size;
                var exaId = "examineTargetIdBmZx"+size;
                $view.find("input[name="+exaName+"]").val(selectData.deptName);
                $view.find("input[name="+exaId+"]").val(selectData.deptId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    $view.find("#bmRc-item").on('click','.addBtn',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('部门选择', '/common/dept', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['500px','600px'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameBmRc"+size;
                var exaId = "examineTargetIdBmRc"+size;
                $view.find("input[name="+exaName+"]").val(selectData.deptName);
                $view.find("input[name="+exaId+"]").val(selectData.deptId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    //车间点击事件
    $view.find("#cjZx-item").on('click','.addBtn2',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('车间选择', '/common/dept', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['500px','600px'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameCjZx"+size;
                var exaId = "examineTargetIdCjZx"+size;
                $view.find("input[name="+exaName+"]").val(selectData.deptName);
                $view.find("input[name="+exaId+"]").val(selectData.deptId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    $view.find("#cjRc-item").on('click','.addBtn2',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('车间选择', '/common/dept', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['500px','600px'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameCjRc"+size;
                var exaId = "examineTargetIdCjRc"+size;
                $view.find("input[name="+exaName+"]").val(selectData.deptName);
                $view.find("input[name="+exaId+"]").val(selectData.deptId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    //班组点击事件
    $view.find("#bzZx-item").on('click','.addBtn3',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('班组选择', '/common/dept', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['500px','600px'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameBzZx"+size;
                var exaId = "examineTargetIdBzZx"+size;
                $view.find("input[name="+exaName+"]").val(selectData.deptName);
                $view.find("input[name="+exaId+"]").val(selectData.deptId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    $view.find("#bzRc-item").on('click','.addBtn3',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('班组选择', '/common/dept', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['500px','600px'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameBzRc"+size;
                var exaId = "examineTargetIdBzRc"+size;
                $view.find("input[name="+exaName+"]").val(selectData.deptName);
                $view.find("input[name="+exaId+"]").val(selectData.deptId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    //项目点击事件
    $view.find("#xmZx-item").on('click','.addBtn4',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('项目选择', 'common/project', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['70%', '85%'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameXmZx"+size;
                var exaId = "examineTargetIdXmZx"+size;
                $view.find("input[name="+exaName+"]").val(selectData.projName);
                $view.find("input[name="+exaId+"]").val(selectData.projId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })

    $view.find("#xmRc-item").on('click','.addBtn4',function () {
        var name = this.getAttribute("name");
        var size = name.slice(13);
        febs.modal.open('项目选择', 'common/project', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['70%', '85%'],
            data:{
                tenantId:$tenantSelect.val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                var exaName = "examineTargetNameXmRc"+size;
                var exaId = "examineTargetIdXmRc"+size;
                $view.find("input[name="+exaName+"]").val(selectData.projName);
                $view.find("input[name="+exaId+"]").val(selectData.projId);
                layer.close(index);
            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });
    })


    form.on('submit(hazardExamineConfig-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
       if(data.tenantId==null || data.tenantId ==''){
            data.tenantId = $tenantSelect.val();
        }
        let itemArr = [];
        let itemDetailArr3 = [];
        let itemDetailArr4 = [];
        let itemDetailArr5 = [];
        let itemDetailArr6 = [];

        $("#bmZx-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclBm" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId3,"1", id, name, number, cycle);//部门检查子表
                itemDetailArr3.push(itemDetail);
            }
        });

        $("#bmRc-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclBm" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId3,"2", id, name, number, cycle);//部门检查子表
                itemDetailArr3.push(itemDetail);
            }
        });

        $("#cjZx-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclCj" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId5,"1", id, name, number, cycle);//车间检查子表
                itemDetailArr4.push(itemDetail);
            }
        });

        $("#cjRc-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclCj" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId5,"2", id, name, number, cycle);//车间检查子表
                itemDetailArr4.push(itemDetail);
            }
        });

        $("#bzZx-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclBz" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId7,"1", id, name, number, cycle);//班组检查子表
                itemDetailArr5.push(itemDetail);
            }
        });

        $("#bzRc-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclBz" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId7,"2", id, name, number, cycle);//班组检查子表
                itemDetailArr5.push(itemDetail);
            }
        });


        $("#xmZx-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length   ==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclXm" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId9,"1", id, name, number, cycle);//项目检查子表
                itemDetailArr6.push(itemDetail);
            }
        });

        $("#xmRc-item").find('.layui-form-item').each(function (i,v) {
            if($($(this).children("div").get(0)).find("input").length   ==3) {
                let name1 = $($(this).children("div").get(0)).find("input").get(0).name;
                let id = $view.find("input[name=" + name1 + "]").val();
                let name2 = $($(this).children("div").get(0)).find("input").get(1).name;
                let name = $view.find("input[name=" + name2 + "]").val();
                let number = $($(this).children("div").get(1)).find("input").val();
                let sss = "examineCyclXm" + name1.slice(17);
                let delId = "examineDtlConfigId" + name1.slice(17);
                let cycle = "";
                $("input[name='"+sss+"']").each(function(index,element){
                    if(element.checked){
                        cycle = element.value;
                    }
                })
                let delIdValue = $view.find("input[name=" + delId + "]").val();
                let itemDetail = new ItemDetail(delIdValue, data.tenantId, data.examineConfigId9,"2", id, name, number, cycle);//项目检查子表
                itemDetailArr6.push(itemDetail);
            }
        });

        let item1 = new Item(data.examineConfigId,data.tenantId,1,data.examineNumber1,data.examineCycl1,data.examineNumber2,data.examineCycl2,null); //公司检查
        let item3 = new Item(data.examineConfigId3,data.tenantId,3,data.examineNumber3,data.examineCycl3,data.examineNumber4,data.examineCycl4,itemDetailArr3);//部门检查
        let item4 = new Item(data.examineConfigId5,data.tenantId,4,data.examineNumber5,data.examineCycl5,data.examineNumber6,data.examineCycl6,itemDetailArr4);//车间检查
        let item5 = new Item(data.examineConfigId7,data.tenantId,5,data.examineNumber7,data.examineCycl7,data.examineNumber8,data.examineCycl8,itemDetailArr5);//班组检查
        let item6 = new Item(data.examineConfigId9,data.tenantId,6,data.examineNumber9,data.examineCycl9,data.examineNumber10,data.examineCycl10,itemDetailArr6);//项目检查

        itemArr.push(item1);
        itemArr.push(item3);
        itemArr.push(item4);
        itemArr.push(item5);
        itemArr.push(item6);

         febs.modal.confirm('保存提示', '是否保存安全检查次数设置？', function () {
             if (data.examineConfigId && data.examineConfigId.length > 0) {
                 febs.postArray(ctx + 'hazardExamineConfigList/update', itemArr, function () {
                     layer.closeAll();
                     febs.alert.success('保存成功');
                 });
             } else {
                 febs.postArray(ctx + 'hazardExamineConfigList', itemArr, function () {
                     layer.closeAll();
                     febs.alert.success('保存成功');
                     reloadPage();
                 });
             }
         });
         return false;

    }
    //安全设置对象
    function Item(_examineConfigId,_tenantId,_examineType,_specialExamineNumber,_specialExamineCycl,_dailyExamineNumber,_dailyExamineCycl,_dtlConfigList) {
        this.examineConfigId = _examineConfigId;
        this.tenantId = _tenantId;
        this.examineType = _examineType;
        this.specialExamineNumber = _specialExamineNumber;
        this.specialExamineCycl = _specialExamineCycl;
        this.dailyExamineNumber = _dailyExamineNumber;
        this.dailyExamineCycl = _dailyExamineCycl;
        this.dtlConfigList = _dtlConfigList;
    }

    function ItemDetail(_examineDtlConfigId,_tenantId,_examineConfigId,_examineCategory,_examineTargetId,_examineTargetName,_examineNumber,_examinCycl) {
        this.examineDtlConfigId = _examineDtlConfigId;
        this.tenantId = _tenantId;
        this.examineConfigId = _examineConfigId;
        this.examineCategory = _examineCategory;
        this.examineTargetId = _examineTargetId;
        this.examineTargetName = _examineTargetName;
        this.examineNumber = _examineNumber;
        this.examineCycl = _examinCycl;

    }

});